package com.caiyi.financial.nirvana.sms.controller;

import com.caiyi.financial.nirvana.sms.param.QueryReportParam;
import com.caiyi.financial.nirvana.sms.service.SmsNotifyService;
import com.youyu.common.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 接收通知相关接口
 */
@Api(description = "接收通知接口")
@RequestMapping("/sms/api/notify")
@RestController
public class SmsNotifyController {

    @Autowired
    private SmsNotifyService smsNotifyService;
    @Autowired
    private HttpServletRequest request;

    @ApiOperation("接收状态报告通知")
    @ApiImplicitParam(name = "body", value = "回调参数", dataType = "String", paramType = "form")
    @RequestMapping(value = "/{gatewayId}", method = {RequestMethod.POST, RequestMethod.GET})
    public String status(@RequestParam Map<String, String> formData, @RequestBody String json, @PathVariable("gatewayId") Integer gatewayId) {
        return smsNotifyService.notifyStatus(formData, gatewayId, json);
    }


    @ApiOperation("主动回调状态报告")
    @ApiImplicitParam(name = "param", value = "主动回调状态报告", required = true, dataType = "QueryReportParam", paramType = "body")
    @RequestMapping(value = "/queryReport", method = {RequestMethod.POST, RequestMethod.GET})
    public Result queryReport(@RequestBody QueryReportParam param) {
        return Result.smsOk(smsNotifyService.queryReport(param, request));
    }

}
